﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RedFoxSpamKiller
{
  public class RedFoxPost: IComment
  {
    private string url;
    private IWebBrowser browser;
    public RedFoxPost( string url, IWebBrowser browser )
    {
      this.url = url;
      this.browser = browser;
      this.browser.navigate(this.url);
    }

    public string GetUserIp()
    {
      HtmlDocument document = browser.getHtmlDocument();
      HtmlElement element = document.GetElementById("dgfiList__ctl3_Ip");
      if (element != null)
        return element.InnerText;
      else
        return "";
    }

    public string GetUserAgent()
    {
      return "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
    }

    public string GetContent()
    {
      HtmlDocument document = browser.getHtmlDocument();
      HtmlElement title = document.GetElementById("dgfiList__ctl3_Title");
      HtmlElement body = document.GetElementById("dgfiList__ctl3_Body");
      return title.InnerText + Environment.NewLine + body.InnerText;
    }

    public string GetAuthor()
    {
      HtmlDocument document = browser.getHtmlDocument();
      HtmlElement element = document.GetElementById("dgfiList__ctl3_Users");
      return element.FirstChild.FirstChild.FirstChild.FirstChild.InnerText;
    }

    public string GetAuthorEmail()
    {
      HtmlDocument document = browser.getHtmlDocument();
      HtmlElement element = document.GetElementById("dgfiList__ctl3_UsersInfo");
      return element.Children[3].GetAttribute("href").Remove(0, 7);
    }
  }
}
